package com.fuhe.chen.vendingmachine.service.impl;

import com.fuhe.chen.vendingmachine.dao.LogDao;
import com.fuhe.chen.vendingmachine.pojo.Log;
import com.fuhe.chen.vendingmachine.service.ILogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class LogServiceImpl implements ILogService {

    @Autowired
    LogDao logDao;

    @Override
    public void addLog(Log log) {
        logDao.addLog(log);
    }

    @Override
    public PageInfo<Log> queryAllLog(int num,int size) {
        PageHelper.startPage(num,size);
        List<Log> all = logDao.findAll();
        PageInfo<Log> logPageInfo = new PageInfo<>(all);
        return logPageInfo;
    }

    @Override
    public PageInfo<Log> queryLogByCondition(String user_id,Date startDate,Date endDate,int num, int size) {
        PageHelper.startPage(num,size);
        List<Log> byCond = logDao.findByCondition(user_id,startDate,endDate);
        PageInfo<Log> logPageInfo = new PageInfo<>(byCond);
        return logPageInfo;
    }
}
